const mongoose = require('../conn')
class BaseModel {

  constructor(modelName, schema) {
    this.model = mongoose.model(modelName, schema);
  }

  async all(filter = {}, field = {}) {
    return await this.model.find(filter, field);
  }

  /**
   * 添加文档信息
   * @param {object} doc 字典对象
   * @return 对象
   */
  async store(doc) {
    return await this.model.create(doc)
  }
}

module.exports = BaseModel